package controller;

import annotation.Controller;
import annotation.DependencyInjection;
import annotation.RequestMapping;
import annotation.Singleton;
import enums.RequestType;
import request.group.GroupCreateRequest;
import request.group.GroupGetRequest;
import request.group.message.GroupMessageListRequest;
import request.group.message.GroupMessagePullRequest;
import request.group.message.GroupMessageSendRequest;
import request.group.relation.GroupListRequest;
import request.group.relation.GroupMemberListRequest;
import request.group.relation.GroupRelationBuildRequest;
import request.group.relation.GroupRelationDestroyRequest;
import response.group.GroupCreateResponse;
import response.group.GroupGetResponse;
import response.group.message.GroupMessageListResponse;
import response.group.message.GroupMessagePullResponse;
import response.group.message.GroupMessageSendResponse;
import response.group.relation.GroupListResponse;
import response.group.relation.GroupMemberListResponse;
import response.group.relation.GroupRelationBuildResponse;
import response.group.relation.GroupRelationDestroyResponse;
import service.GroupService;

@Singleton
@Controller
public class GroupController {
    private GroupService groupService;

    @DependencyInjection
    public GroupController(GroupService groupService) {
        this.groupService = groupService;
    }

    @RequestMapping(RequestType.GroupCreate)
    public GroupCreateResponse createGroup(GroupCreateRequest request) {
        return groupService.createGroup(request.getGroup());
    }

    @RequestMapping(RequestType.GroupGet)
    public GroupGetResponse getGroup(GroupGetRequest request) {
        return groupService.getGroup(request.getGroupId());
    }

    @RequestMapping(RequestType.GroupList)
    public GroupListResponse groupList(GroupListRequest request) {
        return groupService.getListByUsername(request.getUsername());
    }

    @RequestMapping(RequestType.GroupMessageList)
    public GroupMessageListResponse groupMessageList(GroupMessageListRequest request) {
        return groupService.getGroupMessageList(request.getGroupId());
    }

    @RequestMapping(RequestType.GroupMessagePull)
    public GroupMessagePullResponse pullGroupMessage(GroupMessagePullRequest request) {
        return groupService.getLatestMessagesByUsername(request.getGroupId(), request.getUsername());
    }

    @RequestMapping(RequestType.GroupMessageSend)
    public GroupMessageSendResponse sendMessage(GroupMessageSendRequest request) {
        return groupService.sendMessage(request.getGroupMessage());
    }

    @RequestMapping(RequestType.GroupRelationBuild)
    public GroupRelationBuildResponse addGroupRelation(GroupRelationBuildRequest request) {
        return groupService.addGroupRelation(request.getGroupId(), request.getUsername());
    }

    @RequestMapping(RequestType.GroupRelationDestroy)
    public GroupRelationDestroyResponse removeGroupRelation(GroupRelationDestroyRequest request) {
        return groupService.removeGroupRelation(request.getGroupId(), request.getUsername());
    }

    @RequestMapping(RequestType.GroupMemberList)
    public GroupMemberListResponse groupMemberList(GroupMemberListRequest request) {
        return groupService.groupMemberList(request.getGroupId());
    }
}
